package student

import (
	"github.com/zachary/tbox/internal/logic"
	"github.com/zachary/tbox/internal/types"
	"github.com/zachary/tbox/internal/web/util"
)

func addHandler(v *types.StudentAddReq) *util.R {
	stuLogic := logic.NewStuLogic()
	stu, err := stuLogic.Add(v)
	if err != nil {
		return util.Error(err)
	}
	return util.Success(stu)
}

func editHandler(v *types.StudentEditReq) *util.R {
	stuLogic := logic.NewStuLogic()
	err := stuLogic.Edit(v)
	if err != nil {
		return util.Error(err)
	}
	return util.Success("success")
}

func listHandler(v *types.StudentSearchReq) *util.R {
	stuLogic := logic.NewStuLogic()
	stus, err := stuLogic.List(v)
	if err != nil {
		return util.Error(err)
	}
	return util.Success(stus)
}
